﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using S4Store.Domain;

namespace S4Store.Service
{
    public class InformationService : BaseService
    {
        public IQueryable<Information> GetQuery()
        {
            return this.GetQuery<Information>();
        }
        public void AddInformation(Information model)
        {
            if (String.IsNullOrEmpty(model.Content))
            {
                throw new Exception("请填写内容");
            }
            if (String.IsNullOrEmpty(model.Title))
            {
                throw new Exception("请填写标题");
            }
            model.publicdate = DateTime.Now;
            this.GetSet<Information>().Add(model);
        }
        public void ModifyInformation(Information model)
        {
            if (String.IsNullOrEmpty(model.Content))
            {
                throw new Exception("请填写内容");
            }
            if (String.IsNullOrEmpty(model.Title))
            {
                throw new Exception("请填写标题");
            }
        }
        public void DeleteInformation(int id)
        {
            var model = GetQuery().FirstOrDefault(t => t.Id == id);
            if (model != null)
            {
                this.GetSet<Information>().Remove(model);
            }
        }
    }
}
